﻿@using Microsoft.AspNet.Identity

@model Exam.Web.Models.TicketDetailsViewModel
@{
    ViewBag.Title = "Details";
}

<h3>@Model.Title</h3>
<h4>Category: @Model.Category</h4>

<div class="row">
    <div class="span4">
        <p><strong>Author: </strong>@Model.Author</p>
        <p><strong>Priority: </strong>@Model.Priority</p>
    </div>

    <div class="span4">
        @if (!string.IsNullOrEmpty(Model.ScreenshotUrl))
        {
            <img src="@Model.ScreenshotUrl" alt="@Model.Title" width="300" />
        }
    </div>

    <div class="span4">
        @if (!string.IsNullOrEmpty(Model.Description))
        {
            <p><strong>Description: </strong>@Model.Description</p>
        }
    </div>
</div>

<div id="comments">
    @if (Model.Comments != null && Model.Comments.Count() > 0)
    {
        foreach (var comment in Model.Comments)
        {
            <p><strong>@comment.Author: </strong>@comment.Content</p>
        }
    }

</div>

@if (User.Identity.IsAuthenticated)
{
    <div class="row">
        @using (Ajax.BeginForm("Comment", new AjaxOptions
        {
            HttpMethod = "Post",
            InsertionMode = InsertionMode.InsertAfter,
            UpdateTargetId = "comments",
            OnSuccess = "clearTextArea"
        }))
        {
            <strong>Add comment</strong>
            <br />
            @Html.Hidden("Id", Model.Id);
            @Html.TextArea("Content");
            <br />
    <input type="submit" name="Submit comment now" value="Submit comment" />
        }
    </div>
}

<script>
    function clearTextArea() {
        $("#Content").val("");
    }
</script>